package com.qianfeng.search_7004.client;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Envelope;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * author: 田晋宇
 * datetime:2021/10/27 11:06
 * email:853796359@qq.com
 */
@Component
@EnableBinding(ListenClient.class)
public class ListenReceiver {

    @StreamListener("myQueue")
    public void msg(Object msg,
                    @Header(name = AmqpHeaders.CHANNEL) Channel channel,
                    @Header(name = AmqpHeaders.DELIVERY_TAG) Long deliveryTag) throws IOException {
        System.out.println("接收到消息： " + msg);
        channel.basicAck(deliveryTag,false);
    }
}
